<?php

/*
 * контроллер, отвечающий за регистрацию новых юзеров
 */

class Control_RegistrationAction extends Control_Action {

    public function setArgs($args = null) {
        if (null != $args) {
            $this->args = $args;
        }
        return $this;
    }

    public function setView($view) {
        if (null != $view) {
            $this->view = $view;
        }
        return $this;
    }

    public function run() {
        $t = Model_File::getSTime();
        if (null == $this->args) {
            $this->view->setInnerTemplate('reg');
        } else {
            $dbConnection = Control_DbConnection::getConnection();
            $userModel = new Model_User($this->args);
            $mas = Model_UserMapper::saveUser($userModel);
            if (!is_array($mas) && $mas != null) {
                header('location: http://petrovland.site50.net/?control=auth');
            }else{ 
                $this->view->setInnerTemplate('reg');
            }
            
            if (isset($mas[1])) {
                View_View::setError($mas[1]);
            }
        }$_SESSION['time'] = Model_File::getTime($t);
        $_SESSION['memory'] = memory_get_usage();
    }

}